package com.youku.ast;

/**
 * 定义类
 * 
 * @author loda
 *
 */
public class DefClassAst extends Ast {

	public DefClassAst(Ast identifier, Ast parent, Ast block) {
		super(identifier, parent, block);
	}

	public String className() {
		return getChild(0).getTokenValue();
	}

	public String parentName() {
		return getChild(1) == null ? null : getChild(1).getTokenValue();
	}

	public Ast body() {
		return getChild(2);
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder("class " + className());

		if (parentName() != null) {
			builder.append(" extends ").append(parentName());
		}

		return builder.append(body()).toString();
	}

}
